<?php
require("includes/basic.php");
$resource=8;
//echo "select DISTINCT(project_id) from task_assigned_to where task_assigned_to=$resource<br/>";
$getproject=mysql_query("select DISTINCT(project_id) from task_assigned_to where role_id=4 and task_assigned_to=$resource");	

	while($prores= mysql_fetch_array($getproject))
	{
		//echo $prores['project_id']."<br/>";
		$projnames=mysql_query("select * from project_master where project_id=".$prores['project_id']);
		$pronamer=mysql_fetch_array($projnames);
		extract($pronamer);
		
		//echo "select DISTINCT(phase_id) from task_assigned_to where task_assigned_to=$resource and project_id=".$prores['project_id']."<br/>";
		$assphase=mysql_query("select DISTINCT(phase_id) from task_assigned_to where task_assigned_to=$resource and role_id=4 and project_id=".$prores['project_id']);

		while($assphaser=mysql_fetch_array($assphase))
		{
			if($assphaser['phase_id'] > 0)
			{
				//echo $assphaser['phase_id']."<br/>";
				$getphase=mysql_query("select * from phase_master where phase_id=".$assphaser['phase_id']);
				$phaser=mysql_fetch_array($getphase);
				extract($phaser);
				//echo "select DISTINCT(module_id) from task_assigned_to where task_assigned_to=$resource and project_id=".$prores['project_id']." and phase_id=".$assphaser['phase_id']."<br/>";
				$getmodules=mysql_query("select DISTINCT(module_id) from task_assigned_to where task_assigned_to=$resource and project_id=".$prores['project_id']." and role_id=4 and phase_id=".$assphaser['phase_id']);

				while($moduler=mysql_fetch_array($getmodules))
				{
					if($moduler['module_id'] > 0)
					{
						$modulename=mysql_query("select * from module_master where module_id=".$moduler['module_id']);
						$modulenamer=mysql_fetch_array($modulename);
						extract($modulenamer);
						//echo $moduler['module_id']."<br/>";
						//echo "select DISTINCT(task_id) from task_assigned_to where task_assigned_to=$resource and phase_id=".$assphaser['phase_id']." and project_id=".$prores['project_id']." and module_id=".$moduler['module_id']."<br/>";
						$gettask=mysql_query("select DISTINCT(task_id) from task_assigned_to where task_assigned_to=$resource and phase_id=".$assphaser['phase_id']." and project_id=".$prores['project_id']." and module_id=".$moduler['module_id']);
						if(mysql_num_rows($gettask)>0)
						{
							while($taskr=mysql_fetch_array($gettask))
							{
								if($taskr['task_id'] > 0)
								{
									$taskname=mysql_query("select * from task_master where task_id=".$taskr['task_id']);
									$tasknamer=mysql_fetch_array($taskname);
									extract($tasknamer);
									//echo $taskr['task_id']."<br/>";
									$tasks[]="(".$taskr['task_id'].":".$task_title.")";
								}
							}
						}

						$modules[]="<".$moduler['module_id'].":".$module.json_encode($tasks).">;";
						unset($tasks);
						
					}
				}

				$phases[]="{".$assphaser['phase_id'].":".$phase.stripslashes(json_encode($modules))."}|";
				unset($modules);
			}
		}
					
			$projects[]=$prores['project_id'].":".$project_name.stripslashes(json_encode($phases))."-xend-";
			unset($phases);				
		
	}
	
	//echo json_encode($modules)."<br/><br/>";
	//echo json_encode($tasks);
	
	echo stripslashes(str_replace(']', '', str_replace('[', '', str_replace('"', '', json_encode($projects)))));
	

?>
